package com.guchenbo.lssp.autoconfigure;

import com.guchenbo.lssp.domain.LsspSide;
import com.guchenbo.lssp.domain.SessionKind;
import org.springframework.boot.context.properties.ConfigurationProperties;

import static com.guchenbo.lssp.pool.AbstractSessionSource.*;

/**
 * Livy Session池配置
 *
 * @author guchenbo
 */
@ConfigurationProperties(prefix = "chaos.lssp")
public class LsspProperties {

    /**
     * 资源池初始大小
     */
    private int initialSize = DEFAULT_INITIAL_SIZE;
    /**
     * 资源池最大数量
     */
    private int maxActive = DEFAULT_MAX_ACTIVE_SIZE;
    /**
     * 资源池最小数量
     */
    private int minIdle = DEFAULT_INITIAL_SIZE;
    /**
     * 是否开启共享模式
     * 开启共享模式，可以节约session
     */
    private boolean shared = true;
    /**
     * 获取资源超时时间
     */
    private long maxWaitMillis = DEFAULT_MAX_WAIT_MILLIS;
    /**
     * 资源池自我检测时间，用于定时检测并且保持资源池最小数量
     */
    private long timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
    /**
     * livy session kind
     */
    private SessionKind kind = SessionKind.SQL;
    /**
     * lssp server地址，不能以 / 结尾
     */
    private String lsspServerUrl;
    /**
     * 是否需要事先初始化
     * true-启动就初始化
     * false-使用的时候才初始化
     */
    private boolean needInited;

    /**
     * LSSP的位置，服务端 or 客户端
     */
    private LsspSide lsspSide = LsspSide.CLIENT;

    public int getInitialSize() {
        return initialSize;
    }

    public void setInitialSize(int initialSize) {
        this.initialSize = initialSize;
    }

    public int getMaxActive() {
        return maxActive;
    }

    public void setMaxActive(int maxActive) {
        this.maxActive = maxActive;
    }

    public int getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    public boolean isShared() {
        return shared;
    }

    public void setShared(boolean shared) {
        this.shared = shared;
    }

    public long getMaxWaitMillis() {
        return maxWaitMillis;
    }

    public void setMaxWaitMillis(long maxWaitMillis) {
        this.maxWaitMillis = maxWaitMillis;
    }

    public long getTimeBetweenEvictionRunsMillis() {
        return timeBetweenEvictionRunsMillis;
    }

    public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    }

    public SessionKind getKind() {
        return kind;
    }

    public void setKind(SessionKind kind) {
        this.kind = kind;
    }

    public String getLsspServerUrl() {
        return lsspServerUrl;
    }

    public void setLsspServerUrl(String lsspServerUrl) {
        this.lsspServerUrl = lsspServerUrl;
    }

    public boolean isNeedInited() {
        return needInited;
    }

    public void setNeedInited(boolean needInited) {
        this.needInited = needInited;
    }

    public LsspSide getLsspSide() {
        return lsspSide;
    }

    public void setLsspSide(LsspSide lsspSide) {
        this.lsspSide = lsspSide;
    }
}
